cmake_minimum_required(VERSION 3.26)

project(QtWebApp VERSION 1.0.0 LANGUAGES CXX)

find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Quick Widgets Sql Network Multimedia)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Quick Widgets Sql Network Multimedia)

add_library(${PROJECT_NAME}
        httpserver/httpconnectionhandler.cpp httpserver/httpconnectionhandler.h
        httpserver/httpconnectionhandlerpool.cpp httpserver/httpconnectionhandlerpool.h
        httpserver/httpcookie.cpp httpserver/httpcookie.h
        httpserver/httpglobal.cpp httpserver/httpglobal.h
        httpserver/httplistener.cpp httpserver/httplistener.h
        httpserver/httprequest.cpp httpserver/httprequest.h
        httpserver/httprequesthandler.cpp httpserver/httprequesthandler.h
        httpserver/httpresponse.cpp httpserver/httpresponse.h
        httpserver/httpsession.cpp httpserver/httpsession.h
        httpserver/httpsessionstore.cpp httpserver/httpsessionstore.h
        httpserver/staticfilecontroller.cpp httpserver/staticfilecontroller.h
        ## loggin
        logging/dualfilelogger.cpp logging/dualfilelogger.h
        logging/filelogger.cpp logging/filelogger.h
        logging/logger.cpp logging/logger.h
        logging/logglobal.h
        logging/logmessage.cpp logging/logmessage.h
        ## templateengine
        templateengine/template.cpp templateengine/template.h
        templateengine/templatecache.cpp templateengine/templatecache.h
        templateengine/templateglobal.h
        templateengine/templateloader.cpp templateengine/templateloader.h
)

include_directories(${CMAKE_CURRENT_SOURCE_DIR} logging httpserver templateengine)
target_include_directories(${PROJECT_NAME} PRIVATE . logging httpserver templateengine)
target_include_directories(${PROJECT_NAME} PUBLIC . logging httpserver templateengine)

target_compile_options(${PROJECT_NAME} PRIVATE
        $<$<CXX_COMPILER_ID:MSVC>:/bigobj>
        $<$<AND:$<CXX_COMPILER_ID:GNU>,$<BOOL:${GNU_BIG_OBJ_FLAG_ENABLE}>>:-Wa,-mbig-obj>
)

target_link_libraries(${PROJECT_NAME} Qt${QT_VERSION_MAJOR}::Widgets
        Qt${QT_VERSION_MAJOR}::Core
        Qt${QT_VERSION_MAJOR}::Sql
        Qt${QT_VERSION_MAJOR}::Network
        Qt${QT_VERSION_MAJOR}::Multimedia
        Qt${QT_VERSION_MAJOR}::CorePrivate)